#ifndef LOG_GRID_DIALOG_H
#define LOG_GRID_DIALOG_H

#include <gtk/gtk.h>
#include "qso_edit_dialog.h"

class LogGridDialog {
public:
    LogGridDialog();
    ~LogGridDialog();
    
    bool init();
    void show();
    void hide();
    GtkWidget* get_window();
    void populate_log_data();
    void populate_log_data(int page, int pageSize);
    void populate_log_data(const std::string& callsignPrefix);
    void populate_log_data(const std::string& callsignPrefix, int page, int pageSize);
    bool get_selected_record(QSORecord& record);
    
    // 分页相关方法
    int getCurrentPage() const { return currentPage; }
    int getTotalPages() const { return totalPages; }
    int getTotalCount() const { return totalCount; }
    void setCurrentPage(int page) { currentPage = page; }

private:
    GtkBuilder *builder;
    GtkWidget *window;
    GtkWidget *popupMenu;
    
    // 分页相关成员变量
    int currentPage;
    int totalPages;
    int totalCount;
    int pageSize;
    
    // 私有方法
    void create_popup_menu();
    void updatePaginationInfo(); // 更新分页信息显示
    static bool setDataFieldValue(GtkMenuItem *menuitem, gpointer data, const std::string& field, const std::string& value);
    
    // 静态回调函数
    static gboolean on_treeview_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data);
    static void on_menu_delete_clicked(GtkMenuItem *menuitem, gpointer data);
    static void on_menu_edit_clicked(GtkMenuItem *menuitem, gpointer data);
    static void on_prev_page_clicked(GtkButton *button, gpointer data);
    static void on_next_page_clicked(GtkButton *button, gpointer data);
    static void on_first_page_clicked(GtkButton *button, gpointer data);
    static void on_last_page_clicked(GtkButton *button, gpointer data);
    static void on_per_page_changed(GtkComboBox *combo, gpointer data);
    static void on_menu_qsl_sent_clicked(GtkMenuItem *menuitem, gpointer data);
    static void on_menu_qsl_received_clicked(GtkMenuItem *menuitem, gpointer data);
    static void on_menu_qsl_requested_clicked(GtkMenuItem *menuitem, gpointer data);
    static void on_goto_page_clicked(GtkButton *button, gpointer data);
};

#endif // LOG_GRID_DIALOG_H